import request from '@/utils/request'
import StorageUtils from "@/utils/StorageUtils";
// api地址
const api = {
  list: 'shopUserAddress/all',
  defaultId: 'address/defaultId',
  detail: 'shopUserAddress',
  add: 'shopUserAddress',
  edit: 'shopUserAddress',
  setDefault: 'shopUserAddress',
  remove: 'shopUserAddress'
}
let userId=StorageUtils.get('USER_INFO_KEY').id
// 收货地址列表
export const list = (param) => {
  return request.get(api.list, param)
}

// 默认收货地址ID
export const defaultId = (param) => {
  return request.get(api.defaultId, param)
}

// 收货地址详情
export const detail = (addressId) => {
  return request.get(api.detail+'/'+addressId, { id:addressId })
}

// 新增收货地址
export const add = (data) => {
  return request.post(api.add, {address:data.detail,city:data.region[1].label,province:data.region[0].label,town:data.region[2].label,userId:userId,mobile:data.phone,contact:data.name})
}

// 编辑收货地址
export const edit = (addressId, data) => {
  return request.post(api.edit+'/'+userId, {...data })
}

// 设置默认收货地址
export const setDefault = (addressId) => {
  return request.put(api.setDefault+'/'+userId, { id: addressId,isDefault:1,userId:userId})
}

// 删除收货地址
export const remove = (addressId) => {
  return request.delete(api.remove+'/'+addressId, { id:addressId })
}
